package com.xyh.student.controller;

import com.xyh.student.entity.Banji;
import com.xyh.student.entity.ResponseData;
import com.xyh.student.service.BanjiService;
import com.xyh.student.utils.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("banji")
public class BanjiController {

    @Autowired
    private BanjiService banjiService;

    // 1-- 查询全部的班级信息
    @GetMapping("/getBanjis")
    public ResponseData findAllGroups(){
        return this.banjiService.getBanjis();
    }

    // 2-- 修改班级信息
    @PostMapping("/update")
    @ResponseBody
    public ResponseData updateBanji(@RequestBody Banji banji){
        return this.banjiService.update(banji);
    }

    // 3-- 添加新的班级
    @PostMapping("/insert")
    public ResponseData insertBanji(@RequestBody Banji banji){
        System.out.println(banji.toString());
        return this.banjiService.insert(banji);
    }

    // 4-- 删除指定名称的班级
    @PostMapping("/deleteByName")
    public ResponseData deleteByName(String name){
        return this.banjiService.deleteByName(name);
    }

    // 5-- 删除指定名称数组的班级
    @PostMapping("/deletesByIds")
    public ResponseData deletesByNames(@RequestBody String[] ids){
        return this.banjiService.deletesByIds(ids);
    }

    // 6-- 返回全部的班级数
    @GetMapping("/numberOfBanji")
    public ResponseData numberOfBanji(){
        return this.banjiService.numberOfBanji();
    }

    // 7-- 根据名称查询班级
    @GetMapping("/queryByName")
    @ResponseBody
    public ResponseData queryByName(String name){
        return this.banjiService.queryByName(name);
    }

    // 8-- 分页查询
    @GetMapping("/findByPage")
    public ResponseData findByPage(Integer page,Integer size){
        return this.banjiService.findByPage(page,size);
    }

    // 9-- 根据id删除
    @PostMapping("/deleteById/{cid}")
    public ResponseData deleteBanji(@PathVariable("cid") Integer cid){
        System.out.println(cid);
        return this.banjiService.deleteById(cid);
    }

    // 10-- 根据id批量删除
    @PostMapping("/deletesById")
    public ResponseData deletesById(int[] cids){
        return this.banjiService.deletesById(cids);
    }
}
